package com.example.smartwaterapi.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.function.Function;

/**
 * 用户实体类
 */
@Data
@TableName("users")
@Accessors(chain = true)
public class User implements Serializable {

    private static final long serialVersionUID = 1L;
    
    /**
     * 用户ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 用户UUID
     */
    private String uuid;

    /**
     * 手机号
     */
    private String phone;

    /**
     * 昵称
     */
    private String nickname;

    /**
     * 头像
     */
    private String avatar;

    /**
     * 开锁密码（加密存储）
     */
    private String unlockPassword;

    /**
     * 密码盐值
     */
    private String passwordSalt;

    /**
     * 最后修改密码时间
     */
    private LocalDateTime lastPasswordChange;

    /**
     * 微信UnionID
     */
    private String unionid;

    /**
     * 微信小程序OpenID
     */
    private String openid;

    /**
     * 微信公众号OpenID
     */
    private String wxOpenid;

    /**
     * 微信session_key
     */
    private String sessionKey;

    /**
     * 性别 1:男 2:女 0:未知
     */
    private Integer gender;

    /**
     * 年龄
     */
    private Integer age;

    /**
     * 身高(cm)
     */
    private Integer height;

    /**
     * 体重(kg)
     */
    private Double weight;

    /**
     * 每日饮水目标(ml)
     */
    private Integer dailyGoal;

    /**
     * 提醒开关
     */
    private Integer reminderEnabled;

    /**
     * 提醒间隔(分钟)
     */
    private Integer reminderInterval;

    /**
     * 会员等级：basic,silver,gold,diamond
     */
    private String membershipLevel;

    /**
     * 会员到期时间
     */
    private LocalDateTime membershipExpire;

    /**
     * 当前积分
     */
    private Integer points;

    /**
     * 累计积分
    */    private Integer totalPoints;

    /**
     * 状态 1:正常 0:禁用
     */
    private Integer status;

    /**
     * 最后登录时间
     */
    private LocalDateTime lastLoginTime;

    /**
     * 最后登录使用的微信code
     */
    private String lastLoginCode;

    /**
     * 创建时间
     */ 
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    private LocalDateTime updatedAt;
    
    // 静态属性引用方法，用于支持lambda表达式缓存和序列化
    // 参考：https://github.com/baomidou/mybatis-plus/issues/1444
    
    public static <R> Function<User, R> getter(Function<User, R> fn) {
        return fn;
    }
    
    public static Function<User, Long> ID = User::getId;
    
    public static Function<User, String> PHONE = User::getPhone;
    
    public static Function<User, Integer> DAILY_GOAL = User::getDailyGoal;
    
    public static Function<User, Integer> REMINDER_ENABLED = User::getReminderEnabled;
    
    public static Function<User, Integer> REMINDER_INTERVAL = User::getReminderInterval;
    
    public static Function<User, Integer> POINTS = User::getPoints;
    
    public static Function<User, Integer> TOTAL_POINTS = User::getTotalPoints;
    
    public static Function<User, String> LAST_LOGIN_CODE = User::getLastLoginCode;
    
    public static Function<User, LocalDateTime> LAST_LOGIN_TIME = User::getLastLoginTime;
} 